define(function(require, exports, module){
	var Cates = require("cates");
	var Bookmark = require("bookmark");
	var data = require("data");
	var User = require("user");
	var lm = require("login-manager");

	var setting = require("setting");

	var TokenError = require("base").TokenError;

	var user = new User();
	data.on("error", function(e){
		if (e instanceof TokenError) {
			user.show(function(token){
				lm.updateAccessToken(token);
				cates && cates.render();
			});

			bookmark.stopLoading();
			cates.stopLoading();
		} else {
			alert(e.toString());
		}
	});

	var cates = new Cates("cate-list");
	var bookmark = new Bookmark("bookmark-list");
	

	cates.on("cateSelected", function(cateId){
		bookmark.show(cateId);
	});

	cates.on("change", function(){
		chrome.extension.sendMessage({action: "reloadCache"});
	});

	cates.on("bookmarkMoved", function(bookmarkid){
		bookmark.bookmarkMoved(bookmarkid);
	});

	setting.init();
});